<?php
/**
 * Created by PhpStorm.
 * User: edmmss
 * Date: 2018/12/10
 * Time: 11:34
 */

namespace app\modules\registry;


abstract class Registry
{
    const LOGGER = 'logger';

    /**
     * @var array
     */
    public static $storeValues = [];

    /**
     * @var array
     */
    public static $allowedKeys = [
        self::LOGGER,
    ];

    /**
     * 设置组件
     *
     * @date   2018/12/10
     * @author edmmss
     * @param string $key
     * @param $value
     */
    public static function set(string $key, $value)
    {
        if (!in_array($key, self::$allowedKeys)) {
            throw new \InvalidArgumentException('Invalid key given');
        } else {
            self::$storeValues[$key] = $value;
        }
    }

    /**
     * 获取组件
     *
     * @date   2018/12/10
     * @author edmmss
     * @param string $key
     * @return mixed
     */
    public static function get(string $key)
    {
        if (!isset(self::$storeValues[$key])) {
            throw new \InvalidArgumentException('Invalid key given');
        }

        if (!in_array($key, self::$allowedKeys)) {
            throw new \InvalidArgumentException('该组件禁止访问');
        }

        return self::$storeValues[$key];
    }
}